package com.example.writting.ui.interview

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.writting.databinding.ItemInterviewQuestionBinding

class InterviewAdapter : RecyclerView.Adapter<InterviewAdapter.ViewHolder>() {

    private var items = listOf<InterviewQuestion>()

    fun updateItems(newItems: List<InterviewQuestion>) {
        items = newItems
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemInterviewQuestionBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(items[position])
    }

    override fun getItemCount() = items.size

    inner class ViewHolder(private val binding: ItemInterviewQuestionBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(question: InterviewQuestion) {
            binding.questionTitle.text = question.title
            binding.questionAnswer.text = question.answer
        }
    }
} 